const Ajv = require("ajv")
const AjvErrors = require("ajv-errors")
const ajv = new Ajv({ allErrors: true, jsonPointers: true })
AjvErrors(ajv)

function main(data, schema) {
  let validate = ajv.compile(schema)
  let res = validate(data)
  if(res) return res
  let errors = []
  for (const err of validate.errors) {
    errors.push(err.message)
  }
  return errors
}

module.exports = main